<?php

declare(strict_types=1);

namespace App\AsyncQueue;

use Hyperf\AsyncQueue\Annotation\AsyncQueueMessage;
use League\Flysystem\Filesystem;
use Hyperf\Di\Annotation\Inject;
use App\Model\UserMaterial;
use App\Libs\Oss;
use Hyperf\Collection\Arr;

class MaterialAsyncQueue
{
    /**
     * @var Filesystem
     */
    #[Inject]
    private Filesystem $filesystem;
    #[AsyncQueueMessage]
    public function push($params)
    {  
        $string = Oss::getObject($params['url']);
        $data = json_decode($string, true);
        if($data){
            $update = [
                'size'=> Arr::get($data, 'FileSize.value'),
                'ext'=> Arr::get($data, 'Format.value'),
                'width'=> Arr::get($data, 'ImageWidth.value'),
                'height'=> Arr::get($data, 'ImageHeight.value'),
            ];
            UserMaterial::where('id', $params['id'])->update($update);
        }
    }
}
